<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax extends MY_Controller {
    
    public function __construct()
    {
        parent::__construct();
        $this->load->model('ajax_mod');
    }
    
    public function update_num_online()
    {
        try{          
          $num_online = $this->ajax_mod->getNumOnline();
          
          $num_moderators = $this->ajax_mod->updateModActivity();
          $response = array(
                      'ind' => 1,
                      'msg' => "",
                      'num_online' => $num_online,
                      'num_users_online' => ""
                  );
        }
        catch (Exception $e) {

            $response = array(
                'ind' => 0,
                'msg' => 'Following errors occured: <br />' . $e->getMessage(),
                'num_online' => 0
            );
        }
        echo json_encode($response);
    }
    public function update_mod_activity()
    {
        try{          
          $this->ajax_mod->updateModActivity();
          $response = array(
                      'ind' => 1,
                      'msg' => ""
                 );
        }
        catch (Exception $e) {

            $response = array(
                'ind' => 0,
                'msg' => 'Following errors occured: <br />' . $e->getMessage()
             );
        }
        echo json_encode($response);
    }
    
    
    public function update_online_users()
    {
        try{       
          $this->load->model('users_mod');
          $data['online_users'] = $this->users_mod->getOnlineUsers();
          $html = $this->load->view('users/users_list',$data,true);
          $response = array(
                      'ind' => 1,
                      'msg' => "",
                      'html' => $html
                  );
        }
        catch (Exception $e) {

            $response = array(
                'ind' => 0,
                'msg' => 'Following errors occured: <br />' . $e->getMessage(),
                'html' => ''
            );
        }
        echo json_encode($response);
    }
    
    
    
    
    public function change_lang( )
    {      
        try{
          $new_lang = $this->input->post('lang');
          if( $new_lang == 'en' || $new_lang =='de' || $new_lang=='sr' ) {
            $this->session->set_userdata('admin_lang',$new_lang);
            $response = array(
                    'ind' => 1,
                    'msg' => "Language changed"
                );
          } else {
            $this->session->set_userdata('lang','en');
            $response = array(
                    'ind' => 0,
                    'msg' => "Language not changed. Set to English."
                );
          }
          
        }
        catch (Exception $e) {

            $response = array(
                'ind' => 0,
                'msg' => 'Following errors occured: <br />' . $e->getMessage()
            );
        }
        echo json_encode($response);        
    }
       
    
    
    
}

/* End of file ajax.php */
/* Location: ./application/controllers/ajax.php */